﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using BneyBaruch.Ingest.Core.WorkflowCommunication.Extensions;

namespace BneyBaruch.Ingest.Core.WorkflowCommunication
{
    public class WorkflowServiceHostBase : ServiceHost
    {
        #region Constructors

        // Summary:
        //     Initializes a new instance of the WorkflowServiceHost class with
        //     the instance of the service and its base addresses specified.
        //
        // Parameters:
        //   singletonInstance:
        //     The instance of the hosted service.
        //
        //   baseAddresses:
        //     An System.Array of type System.Uri that contains the base addresses for the
        //     hosted service.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     singletonInstance is null.
        public WorkflowServiceHostBase(object singletonInstance, params Uri[] baseAddresses) 
            : base(singletonInstance, baseAddresses)
        {
            AddWorkflowRuntimePerServiceContainerExtension();
        }

        // Summary:
        //     Initializes a new instance of the WorkflowServiceHost class with
        //     the type of service and its base addresses specified.
        //
        // Parameters:
        //   serviceType:
        //     The type of hosted service.
        //
        //   baseAddresses:
        //     An array of type System.Uri that contains the base addresses for the hosted
        //     service.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     serviceType is null.
        public WorkflowServiceHostBase(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            AddWorkflowRuntimePerServiceContainerExtension();
        }

        #endregion

        #region Private Methods

        private void AddWorkflowRuntimePerServiceContainerExtension()
        {
            // Instantiate and add the extension which hosts our workflow runtime
            WorkflowRuntimePerServiceContainer workflowRuntimePerServiceContainerExtension =
                new WorkflowRuntimePerServiceContainer("WorkflowRuntimeConfig");

            this.Extensions.Add(workflowRuntimePerServiceContainerExtension);
        }

        #endregion
    }
}
